package data_retrieval;

import info.androidhive.slidingmenu.R;
import java.util.List;
import mindshare.LoadContent;

import org.apache.http.NameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.view.MenuItem;
import android.widget.Toast;

public class ManageFriendship extends LoadContent {
	MenuItem menu;
	String state;
	String action;

	public ManageFriendship(Context context, List<NameValuePair> param, String data, MenuItem m, String action) {
		super(context, param, data);
		this.menu = m;
		this.action=action;
	}
	
	
	@Override
	protected void onPreExecute() {
		menu.setActionView(R.layout.action_progressbar);
		menu.expandActionView();
	}

	protected String doInBackground(String... args) {
		if (action.equals("add")) script = "addFriend.php";
		else if (action.equals("accept")) script = "acceptFriend.php";
		else if (action.equals("delete")) script = "deleteFriend.php";
		else if (action.equals("deleteRequest")) script = "deleteFriendRequest.php";
		JSONObject json = jParser.makeHttpRequest(url + script, param);
		try {
			state = json.getString(data);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}

	protected void onPostExecute(String file_url) {
		Toast.makeText(c, state, Toast.LENGTH_SHORT).show();
		menu.collapseActionView();
		menu.setActionView(null);
	}
}